﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;



namespace ScriptEase
{
    [DataContract]
    public class ProjectConfiguration
    {
        [OnDeserializing]
        public void BeforeDeserialization(StreamingContext ctx)
        {
            // Set default values
            this.IncludeManaged = true;
            this.ReadonlyManaged = true;
            this.IncludeNonCustomizable = true;
        }


        private string _baseDirectory;

        // Used to internally store the filename from which the 
        // configuration was loaded
        public string FilePath { get; set; }

        [DataMember(Order = 10, IsRequired = false, EmitDefaultValue = false)]
        public Guid ConnectionId { get; set; }

        /// <summary>
        /// A relative or absolute path to the local WebResource directory.
        /// </summary>
        /// <remarks>
        /// A realtive path is specified relative to the project configuration file directory (*.seproj)
        /// </remarks>
        [DataMember(Order = 20, IsRequired = true)]
        public string BaseDirectory
        {
            get { return _baseDirectory; }
            set
            {
                _baseDirectory = FileNDirectory.AlignDirectoryName(value);
            }
        }


        [DataMember(Order = 30)]
        public bool AutoUpdate { get; set; }

        [DataMember(Order = 40)]
        public bool AutoPublish { get; set; }

        [DataMember(Order = 50)]
        public string RemovePublisherPrefixes { get; set; }

        [DataMember(Order = 60)]
        public bool IncludeManaged { get; set; }


        /// <summary>
        /// Gets or sets a value indicating whether managed scriptds are read/only.
        /// </summary>
        /// <value>
        /// Read/Only script will not be uploaded to CRM. If ScriptEase recognizes 
        /// any local change this will be overridden by download the latest version from CRM.
        /// </value>
        [DataMember(Order = 65)]
        public bool ReadonlyManaged { get; set; }


        //[Obsolete]
        //[DataMember(Order = 70)]
        //public bool IncludeSystem { get; set; }

        [DataMember(Order = 71)]
        public bool IncludeNonCustomizable { get; set; }

        
        [Obsolete]
        [DataMember]
        public bool FilenameGuessing { get; set; }

        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public List<string> KnownOrganizations { get; set; }

        /// <summary>
        /// The name of a file that contains WebResource to local file name (path) mappings.
        /// </summary>
        /// <remarks>
        /// If not set, ScriptEase assumes the local script directory structure matches 
        /// the namespace/WebResource name structure in CRM.
        /// </remarks>
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string MappingFileName { get; set; }

        /// <summary>
        /// The name of a MEF contract that is used 
        /// to read the <see cref="MappingFileName">mapping file</see>
        /// </summary>
        /// <remarks>
        /// If no contract is specified the first available reader ist used (assuming, just one is available).
        /// </remarks>
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string MappingFileReaderContractName { get; set; }

    }
}